package com.wuzheng.wisgo.sanitation.devtools.service;

import com.baomidou.mybatisplus.mapper.SqlRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author：hibon
 * @date：Created in 2019/08/17
 * @description：获取数据库所有的表
 * @modified By：
 * @version: 1.0
 */
@Service
public class TableService {

    @Value("${spring.datasource.db-name}")
    private String dbName;

    /**
     * 获取当前数据库所有的表信息
     */
    public List<Map<String, Object>> getAllTables() {
        String sql = "select t1.tablename as  \"tableName\", obj_description(relfilenode, 'pg_class') as \"tableComment\" from pg_tables t1, pg_class t2 where t1.schemaname='" + dbName + "' and t1.tablename = t2.relname";
        return SqlRunner.db().selectList(sql);
    }
}
